<template>
  <div class="app-container">
    <el-card class="box-card">
      <el-form :inline="true" :model="listQuery">
        <el-form-item>
          <el-date-picker
            size="small"
            v-model="listQuery.search_date"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-search"
            @click.native="handleFilter"
            >查询</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            >新增借条</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button
            type="danger"
            icon="el-icon-delete"
            size="mini"
            @click="handleBatchDelete"
            >批量删除</el-button
          >
        </el-form-item>
        <el-form-item>
          <el-button
            type="success"
            icon="el-icon-download"
            size="mini"
            @click="createLoanNotes"
            >生成借条</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        :data="loans"
        border
        v-loading="listLoading"
        fit
        highlight-current-row
        style="width: 100%"
        size="small"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" align="center"> </el-table-column>
        <el-table-column
          v-for="column in tableColumns"
          :key="column.key"
          :label="column.title"
          :prop="column.key"
          :align="column.align ? column.width : 'center'"
          :width="column.width ? column.width : ''"
        >
          <template slot-scope="scope">
            <div
              v-if="column.key == 'lender_name' || column.key == 'cate_name'"
            >
              <el-link type="primary" @click="handleEdit(scope)" size="mini">{{
                scope.row[column.key]
              }}</el-link>
            </div>
            <div v-else>
              {{ scope.row[column.key] }}
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="200px">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-edit"
              @click="handleEdit(scope)"
              >编辑</el-button
            >
            <el-button
              type="danger"
              size="mini"
              icon="el-icon-delete"
              @click="handleDelete(scope)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.page_size"
        @pagination="getMyLoanNotes"
      />
    </el-card>
    <!-- 借条登记 -->
    <el-dialog
      :visible.sync="dialogVisible"
      title="借条登记"
      width="75%"
      destroy-on-close
      top="10px"
    >
      <el-form
        :model="form"
        ref="formRef"
        label-width="130px"
        label-position="right"
        style="width: 100%; padding: 0 30px"
        status-icon
        size="mini"
      >
        <el-row>
          <el-col :span="12">
            <el-form-item label="身份属性" prop="cate">
              <el-select v-model="form.cate" placeholder="身份属性" clearable>
                <el-option
                  v-for="item in cates"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="出借人姓名" prop="lender_name">
              <el-input
                type="String"
                v-model="form.lender_name"
                placeholder="出借人姓名"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="出借人身份证" prop="lender_ident">
              <el-input
                type="String"
                v-model="form.lender_ident"
                placeholder="出借人身份证"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="借款人姓名" prop="borrower_name">
              <el-input
                type="String"
                v-model="form.borrower_name"
                placeholder="借款人姓名"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="借款人身份证" prop="borrower_ident">
              <el-input
                type="String"
                v-model="form.borrower_ident"
                placeholder="借款人身份证"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="共同借款人姓名" prop="co_borrower_name">
              <el-input
                type="String"
                v-model="form.co_borrower_name"
                placeholder="共同借款人姓名"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="共同出借人身份证" prop="co_borrower_ident">
              <el-input
                type="String"
                v-model="form.co_borrower_ident"
                placeholder="共同出借人身份证"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="借款人家庭地址" prop="borrower_address">
              <el-input
                type="String"
                v-model="form.borrower_address"
                placeholder="借款人家庭地址"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="借款人手机" prop="borrower_phone">
              <el-input
                type="String"
                v-model="form.borrower_phone"
                placeholder="借款人手机"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="借款人微信" prop="borrower_wechat">
              <el-input
                type="String"
                v-model="form.borrower_wechat"
                placeholder="借款人微信"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="借款人单位地址" prop="borrower_unit_address">
              <el-input
                type="String"
                v-model="form.borrower_unit_address"
                placeholder="借款人单位地址"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="借款人单位电话" prop="borrower_unit_phone">
              <el-input
                type="String"
                v-model="form.borrower_unit_phone"
                placeholder="借款人单位电话"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="保证人姓名" prop="guarantor_name">
              <el-input
                type="String"
                v-model="form.guarantor_name"
                placeholder="保证人姓名"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="保证人身份证" prop="guarantor_ident">
              <el-input
                type="String"
                v-model="form.guarantor_ident"
                placeholder="保证人身份证"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="保证人家庭地址" prop="guarantor_address">
              <el-input
                type="String"
                v-model="form.guarantor_address"
                placeholder="保证人家庭地址"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="保证人手机" prop="guarantor_phone">
              <el-input
                type="String"
                v-model="form.guarantor_phone"
                placeholder="保证人手机"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="保证人微信" prop="guarantor_wechat">
              <el-input
                type="String"
                v-model="form.guarantor_wechat"
                placeholder="保证人微信"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="保证人单位地址" prop="guarantor_unit_address">
              <el-input
                type="String"
                v-model="form.guarantor_unit_address"
                placeholder="保证人单位地址"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="保证人单位电话" prop="guarantor_unit_phone">
              <el-input
                type="String"
                v-model="form.guarantor_unit_phone"
                placeholder="保证人单位电话"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="借款用途" prop="loan_usage">
              <el-input
                type="String"
                v-model="form.loan_usage"
                placeholder="借款用途"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="借款金额" prop="loan_money">
              <el-input
                type="String"
                v-model="form.loan_money"
                placeholder="借款金额"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="借款金额大写" prop="loan_word_money">
              <el-input
                type="String"
                v-model="form.loan_word_money"
                placeholder="借款金额大写"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="借款期限" prop="loan_term">
              <el-input
                type="String"
                v-model="form.loan_term"
                placeholder="借款期限"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="开始日期" prop="loan_begin_date">
              <el-date-picker
                v-model="form.loan_begin_date"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                placeholder="截止日期"
                clearable
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="截止日期" prop="loan_end_date">
              <el-date-picker
                v-model="form.loan_end_date"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                placeholder="截止日期"
                clearable
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="还款账户名称" prop="repay_account_name">
              <el-input
                type="String"
                v-model="form.repay_account_name"
                placeholder="还款账户名称"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="还款账户" prop="repay_account">
              <el-input
                type="String"
                v-model="form.repay_account"
                placeholder="还款账户"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="还款开户银行" prop="repay_bank">
              <el-input
                type="String"
                v-model="form.repay_bank"
                placeholder="还款开户银行"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计息单位时间" prop="interest_unit_time">
              <el-input
                type="String"
                v-model="form.interest_unit_time"
                placeholder="计息单位时间"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="利息" prop="interest">
              <el-input
                type="String"
                v-model="form.interest"
                placeholder="利息"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="利息结算时间" prop="interest_settle_time">
              <el-date-picker
                v-model="form.interest_settle_time"
                type="date"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
                placeholder="利息结算时间"
                clearable
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="日违约金" prop="date_penalty">
              <el-input
                type="String"
                v-model="form.date_penalty"
                placeholder="日违约金"
                clearable
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="抵押物" prop="collateral">
              <el-input
                type="String"
                v-model="form.collateral"
                placeholder="抵押物"
                clearable
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer">
        <el-button size="small" type="danger" @click="dialogVisible = false"
          >取消</el-button
        >
        <el-button
          size="small"
          type="primary"
          @click="handleSave(false)"
          v-if="dialogType != 'detail'"
          >保存</el-button
        >
        <el-button
          type="primary"
          size="small"
          v-if="dialogType == 'new'"
          @click="handleSave(true)"
          >保存并新增</el-button
        >
      </div>
    </el-dialog>
    <el-dialog
      title="正在下载，请等待"
      :visible.sync="progressShow"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="false"
      width="20%"
    >
      <div style="text-align: center">
        <el-progress :percentage="percentage" type="circle"></el-progress>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import {
  getLoanNotes,
  addLoanNote,
  updateLoanNote,
  delLoanNote,
  delLoanNotes,
  createNotes,
} from "@/api/document";

import { formatDateTime } from "@/utils/datetime";
import Pagination from "@/components/Pagination";

const defaultForm = {
  id: null,
  cate: null,
  lender_name: "",
  lender_ident: "",
  borrower_name: "",
  borrower_ident: "",
  co_borrower_name: "",
  co_borrower_ident: "",
  borrower_address: "",
  borrower_phone: "",
  borrower_wechat: "",
  borrower_unit_address: "",
  borrower_unit_phone: "",
  guarantor_name: "",
  guarantor_ident: "",
  guarantor_address: "",
  guarantor_phone: "",
  guarantor_wechat: "",
  guarantor_unit_address: "",
  guarantor_unit_phone: "",
  loan_usage: "",
  loan_money: 0,
  loan_word_money: "",
  loan_term: 0,
  loan_begin_date: null,
  loan_end_date: null,
  repay_account_name: "",
  repay_account: "",
  repay_bank: "",
  interest_unit_time: "",
  interest: 0,
  interest_settle_time: null,
  date_penalty: "",
  collateral: "",
  user: null,
};

export default {
  name: "Loan",
  data() {
    return {
      form: Object.assign({}, defaultForm),

      // formRules: {
      //   case_type: [
      //     { required: true, message: "请选择案件类型", trigger: "blur" },
      //   ],
      //   client: [
      //     {
      //       type: "string",
      //       required: true,
      //       message: "请输入委托人",
      //       trigger: "blur",
      //     },
      //   ],
      //   telephone: [
      //     {
      //       type: "string",
      //       required: true,
      //       message: "请输入电话",
      //       trigger: "blur",
      //     },
      //   ],
      //   party: [
      //     {
      //       type: "string",
      //       required: true,
      //       message: "请输入当事人",
      //       trigger: "blur",
      //     },
      //   ],
      //   reason: [
      //     {
      //       type: "string",
      //       required: true,
      //       validator: checkReason,
      //       trigger: ["blur", "change"],
      //     },
      //   ],
      //   court: [
      //     {
      //       type: "string",
      //       required: true,
      //       message: "请输入管辖法院",
      //       trigger: "blur",
      //     },
      //   ],
      //   recv_lawyer: [
      //     {
      //       type: "string",
      //       required: true,
      //       message: "请输入收案律师",
      //       trigger: "blur",
      //     },
      //   ],
      //   level: [
      //     {
      //       type: "string",
      //       required: true,
      //       message: "请输入审级",
      //       trigger: "blur",
      //     },
      //   ],
      //   lead_lawyer: [
      //     {
      //       required: true,
      //       message: "请输入主办律师",
      //       trigger: "blur",
      //     },
      //   ],
      //   register_time: [
      //     {
      //       type: "string",
      //       required: true,
      //       message: "请输入立案时间",
      //       trigger: "blur",
      //     },
      //   ],
      //   open_time: [
      //     {
      //       type: "string",
      //       required: true,
      //       message: "请输入开庭时间",
      //       trigger: "blur",
      //     },
      //   ],
      //   oppo_party: [
      //     {
      //       type: "string",
      //       required: true,
      //       message: "请输入对方当事人",
      //       trigger: "blur",
      //     },
      //   ],
      //   end_time: [
      //     {
      //       type: "string",
      //       required: true,
      //       message: "请输入结案时间",
      //       trigger: "blur",
      //     },
      //   ],
      //   case_num: [
      //     {
      //       type: "string",
      //       message: "请输入案号",
      //       required: true,
      //       trigger: "blur",
      //     },
      //   ],
      // },

      tableColumns: [
        {
          key: "cate_name",
          title: "身份属性",
          width: "100",
        },
        {
          key: "lender_name",
          title: "出借人姓名",
          width: "120",
        },
        {
          key: "lender_ident",
          title: "出借人身份证",
          width: "150",
        },
        {
          key: "borrower_name",
          title: "借款人姓名",
          width: "120",
        },
        {
          key: "borrower_ident",
          title: "借款人身份证",
          width: "150",
        },
        {
          key: "co_borrower_name",
          title: "共同借款人姓名",
          width: "120",
        },
        {
          key: "co_borrower_ident",
          title: "共同出借人身份证",
          width: "140",
        },
        {
          key: "borrower_address",
          title: "借款人家庭地址",
          width: "240",
        },
        {
          key: "borrower_phone",
          title: "借款人手机",
          width: "120",
        },
        {
          key: "borrower_wechat",
          title: "借款人微信",
          width: "120",
        },
        {
          key: "borrower_unit_address",
          title: "借款人单位地址",
          width: "220",
        },
        {
          key: "borrower_unit_phone",
          title: "借款人单位电话",
          width: "120",
        },
        {
          key: "guarantor_name",
          title: "保证人姓名",
          width: "120",
        },
        {
          key: "guarantor_ident",
          title: "保证人身份证",
          width: "120",
        },
        {
          key: "guarantor_address",
          title: "保证人家庭地址",
          width: "120",
        },
        {
          key: "guarantor_phone",
          title: "保证人手机",
          width: "120",
        },
        {
          key: "guarantor_wechat",
          title: "保证人微信",
          width: "120",
        },
        {
          key: "guarantor_unit_address",
          title: "保证人单位地址",
          width: "220",
        },
        {
          key: "guarantor_unit_phone",
          title: "保证人单位电话",
          width: "120",
        },
        {
          key: "loan_usage",
          title: "借款用途",
          width: "140",
        },
        {
          key: "loan_money",
          title: "借款金额",
          width: "100",
        },
        {
          key: "loan_word_money",
          title: "借款金额大写",
          width: "180",
        },
        {
          key: "loan_term",
          title: "借款期限",
          width: "100",
        },
        {
          key: "loan_begin_date",
          title: "开始日期",
          width: "120",
        },
        {
          key: "loan_end_date",
          title: "截止日期",
          width: "120",
        },
        {
          key: "repay_account_name",
          title: "还款账户名称",
          width: "120",
        },
        {
          key: "repay_account",
          title: "还款账户",
          width: "120",
        },
        {
          key: "repay_bank",
          title: "还款开户银行",
          width: "120",
        },
        {
          key: "interest_unit_time",
          title: "计息单位时间",
          width: "120",
        },
        {
          key: "interest",
          title: "利息",
          width: "120",
        },
        {
          key: "interest_settle_time",
          title: "利息结算时间",
          width: "120",
        },
        {
          key: "date_penalty",
          title: "日违约金",
          width: "120",
        },
        {
          key: "collateral",
          title: "抵押物",
          width: "120",
        },
      ],
      title: "借条",

      dialogVisible: false,
      dlgLetterVisible: false,

      dialogType: "new",
      loans: [],
      cates: [
        { id: 0, name: "出借人" },
        { id: 1, name: "借款人" },
        { id: 2, name: "保证人" },
      ],
      total: 0,
      listLoading: true,
      selections: [],
      listQuery: {
        page: 1,
        page_size: 20,
        search_date: [],
      },
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      progressShow: false,
      percentage: 0,
    };
  },
  computed: {
    ...mapGetters(["uid"]),
  },
  components: {
    Pagination,
  },
  created() {
    this.getMyLoanNotes();
  },
  methods: {
    getMyLoanNotes() {
      this.listLoading = true;
      getLoanNotes(this.listQuery)
        .then((res) => {
          this.loans = res.results;
          this.listLoading = false;
          this.total = res.count;
        })
        .catch((error) => {
          console.log(error);
          this.$message.error("获取数据失败!");
          this.listLoading = false;
        });
    },

    createLoanNotes() {
      const data = {
        search_date: this.listQuery.search_date,
      };

      this.progressShow = true;
      this.percentage = 0;
      createNotes(data, (progressEvent) => {

        let progressBar = Math.round(
          (progressEvent.loaded / progressEvent.total) * 100
        );
        //接收进度为99%的时候需要留一点前端编译的时间
        if (progressBar >= 99) {
          this.percentage = 99;
          this.$message.success("下载完成。");
        } else {
          this.percentage = progressBar;
          // this.$message("正在下载，请稍等。");
        }
      })
        .then((res) => {
          console.log(res);
          if (res.data.type == "application/octet-stream") {
            let filename = res.headers["content-disposition"];
            const blob = new Blob([res.data]);
            let downloadElement = document.createElement("a");
            var href = window.URL.createObjectURL(blob); //创建下载的链接
            downloadElement.href = href;
            downloadElement.download = decodeURI(
              filename.split("filename=")[1]
            ); //下载后文件名

            document.body.appendChild(downloadElement);
            downloadElement.click(); //点击下载
            document.body.removeChild(downloadElement); //下载完成移除元素
            window.URL.revokeObjectURL(href); //释放掉blob对象
            this.progressShow = false;
            this.percentage = 0;
          }
        })
        .catch((error) => {
          this.$message.error("获取数据失败:" + error);
          this.progressShow = false;
          this.percentage = 0;
        });

    },

    handleSelectionChange(val) {
      this.selections = val.map((item) => item.id);
    },
    // 查询
    handleFilter() {
      this.listQuery.page = 1;
      this.getMyLoanNotes();
    },

    // 增加
    handleAdd() {
      this.form = Object.assign({}, defaultForm);
      this.dialogType = "new";
      this.dialogVisible = true;

      this.$nextTick(() => {
        this.dlgSearchVisible = false;
        this.$refs.formRef.clearValidate();
      });
    },
    // 修改
    handleEdit(scope) {
      this.form = Object.assign({}, scope.row);
      this.dialogType = "edit";
      this.dialogVisible = true;
      this.$nextTick(() => {
        this.$refs.formRef.clearValidate();
      });
    },
    //批量删除
    handleBatchDelete() {
      if (this.selections.length == 0) {
        this.$message.warning("请选择要删除记录");
        return;
      }
      this.$confirm("确定要删除选中记录吗?", "删除提示：", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const sel_ids = {
            select_ids: this.selections,
          };
          const res = await delLoanNotes(sel_ids);

          this.getMyLoanNotes();
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch((err) => {
          this.$message({
            type: "success",
            message: "删除失败!" + err,
          });
        });
    },
    // 删除
    handleDelete({ $index, row }) {
      this.$confirm("确定要删除该案件吗?", "删除提示：", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const res = await delLoanNote(row.id);
          if (res) {
            this.getMyLoanNotes();
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          }
        })
        .catch((err) => {
          console.error(err);
        });
    },
    // 保存操作
    async handleSave(flag) {
      this.$refs.formRef.validate(async (valid) => {
        if (!valid) return;

        const isEdit = this.dialogType === "edit";
        let res = null;
        if (this.form.user == null || this.form.user == undefined) {
          this.form.user = this.uid;
        }
        if (isEdit) {
          res = await updateLoanNote(this.form);
        } else {
          res = await addLoanNote(this.form);
        }

        this.getMyLoanNotes();

        const { lender_name, lender_ident } = res;

        if (flag) {
          this.form = Object.assign({}, defaultForm);
        } else {
          this.dialogVisible = false;
        }

        this.$notify({
          title: "Success",
          dangerouslyUseHTMLString: true,
          message: `
              <div>出借人姓名: ${lender_name}</div>
              <div>出借人身份证: ${lender_ident}</div>
            `,
          type: "success",
        });
      });
    },
  },
};
</script>

<style lang='scss' scoped>
</style>